/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/*******************************************************************************
    FILE NAME:		fifo.h

    PROJECT:		Linux ECAN527/1000 driver, library, and sample programs

    FILE DESCRIPTION:	This header file contains definitions for a fast
    			generic array-based queue.

    Copyright (c) 2004 RTD Embedded Technologies, Inc.

    For driver version, compiler, and target information, please refer to the
    file README.TXT.
*******************************************************************************/

#ifndef  _ECAN_FIFO_H
# define _ECAN_FIFO_H

# include <ecan_types.h>	// size_t


struct df_fifo;
typedef struct df_fifo df_fifo_t;


// create a new FIFO control structure
df_fifo_t* df_fifo_create(size_t slot_size, size_t reserved_slots);

void       df_fifo_delete(df_fifo_t* f);


// allocate FIFO space
// returns 0 on success or -ENOMEM
int    df_fifo_allocate  (df_fifo_t* f, size_t      size);

// free FIFO space
void   df_fifo_free      (df_fifo_t* f);

// clear FIFO contents
void   df_fifo_clear     (df_fifo_t* f);

int    df_fifo_is_empty  (df_fifo_t* f);
int    df_fifo_is_full   (df_fifo_t* f);

size_t df_fifo_all__slots(df_fifo_t* f);
size_t df_fifo_used_slots(df_fifo_t* f);
size_t df_fifo_free_slots(df_fifo_t* f);


// claim free tail slot and advance FIFO tail
// returns claimed tail slot pointer or NULL
void* df_fifo_get_free_tail_slot(df_fifo_t* f);

// claim free or reserved tail slot and advance FIFO tail
// returns claimed tail slot pointer or NULL
void* df_fifo_get_reserved_free_tail_slot(df_fifo_t* f);

// returns pointer to filled head slot or NULL if there is no filled slots
void* df_fifo_get_head_slot(df_fifo_t* f);


// release filled head slot and advance FIFO head
void df_fifo_release_head_slot(df_fifo_t* f);


#endif	/* _ECAN_FIFO_H */
